unit Image;

interface

uses
  Database,
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, ExtCtrls, Gauges, StdCtrls, MPlayer, Buttons;

type
  TFormImagery = class(TForm)
    PanelImage: TPanel;
    Image: TImage;
    MainMenu: TMainMenu;
    MenuMain2: TMenuItem;
    MenuExit: TMenuItem;
    MenuEscape: TMenuItem;
    MenuHelp: TMenuItem;
    MenuCtrlTab: TMenuItem;
    MenuCtrlTab2: TMenuItem;
    MenuAutotyper: TMenuItem;
    MenuChat: TMenuItem;
    MenuTell: TMenuItem;
    MenuStatus: TMenuItem;
    MenuMessage: TMenuItem;
    MenuFToolbar: TMenuItem;
    MenuPanic: TMenuItem;
    PanelGauge: TPanel;
    GaugeEnemy: TGauge;
    PopupImage: TPopupMenu;
    PopupSelectBackgroundColor: TMenuItem;
    DialogColor: TColorDialog;
    MenuStayOnTop: TMenuItem;
    PanelLabel: TPanel;
    LabelText: TLabel;
    MenuShowGauge: TMenuItem;
    MenuShowImageLabel: TMenuItem;
    N1: TMenuItem;
    MenuClear: TMenuItem;
    PopupClearImage: TMenuItem;
    MenuBColor: TMenuItem;
    MenuFiltered: TMenuItem;
    MenuVariables: TMenuItem;
    MenuMap: TMenuItem;
    Canvas1: TMenuItem;
    PanelAVI: TPanel;
    MP: TMediaPlayer;
    PanelMP: TPanel;
    BtnPlay: TSpeedButton;
    BtnStop: TSpeedButton;
    MenuAutoRepeat: TMenuItem;
    procedure MenuExitClick(Sender: TObject);
    procedure MenuEscapeClick(Sender: TObject);
    procedure MenuHelpClick(Sender: TObject);
    procedure MenuCtrlTabClick(Sender: TObject);
    procedure MenuAutotyperClick(Sender: TObject);
    procedure MenuPanicClick(Sender: TObject);
    procedure PopupSelectBackgroundColorClick(Sender: TObject);
    procedure MenuStayOnTopClick(Sender: TObject);
    procedure MenuShowGaugeClick(Sender: TObject);
    procedure ImageDblClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure MPNotify(Sender: TObject);
    procedure BtnPlayClick(Sender: TObject);
    procedure MenuAutoRepeatClick(Sender: TObject);
  private
    { Private declarations }
    procedure WMGetMinMaxInfo(var MSG: Tmessage); message WM_GETMINMAXINFO;
  public
    { Public declarations }
    avis: TStringList;
    procedure UpdatePanels;
    procedure DoPlay;
  end;

var
  FormImagery: TFormImagery;
  isplaying: boolean;

implementation

uses Main;

{$R *.DFM}

procedure TFormImagery.FormCreate(Sender: TObject);
begin
  isplaying:=false;
  PanelMP.width:=0;
  avis:=TStringList.create;
end;

procedure TFormImagery.WMGetMinMaxInfo(var MSG: Tmessage);
begin
  inherited;
  with PMinMaxInfo(MSG.lparam)^ do begin
    with ptMinTrackSize do begin
      X := 136;
      Y := 155;
    end;
    with ptMaxTrackSize do begin
      X := 9999;
      Y := 9999;
    end;
  end;
end;

procedure TFormImagery.MenuExitClick(Sender: TObject);
begin
  close;
end;

procedure TFormImagery.MenuEscapeClick(Sender: TObject);
begin
  FormMain.show;
end;

procedure TFormImagery.MenuHelpClick(Sender: TObject);
begin
  Datawell.Help('imagery');
end;

procedure TFormImagery.MenuCtrlTabClick(Sender: TObject);
begin
  if TMenuItem(sender).tag = 0 then FormMain.NextScreen(6)
  else FormMain.PriorScreen(6);
end;

procedure TFormImagery.MenuAutotyperClick(Sender: TObject);
begin
  FormMain.OpenFloater(TComponent(sender).tag);
end;

procedure TFormImagery.MenuPanicClick(Sender: TObject);
begin
  FormMain.MenuPanic.click;
end;

procedure TFormImagery.PopupSelectBackgroundColorClick(Sender: TObject);
begin
  DialogColor.color:=PanelImage.color;
  if not DialogColor.execute then exit;
  PanelImage.color:=DialogColor.color;
end;

procedure TFormImagery.MenuStayOnTopClick(Sender: TObject);
begin
  TMenuItem(sender).checked:=not TMenuItem(sender).checked;
  if MenuStayOnTop.checked = true then formstyle:=fsstayontop
  else formstyle:=fsnormal;
end;

procedure TFormImagery.MenuShowGaugeClick(Sender: TObject);
begin
  TMenuItem(sender).checked:=not TMenuItem(sender).checked;
  UpdatePanels;
end;

procedure TFormImagery.UpdatePanels;
begin
  if MenuShowGauge.checked then PanelGauge.width:=18 else PanelGauge.width:=0;
  if MenuShowImageLabel.checked then PanelLabel.height:=21 else PanelLabel.height:=0;
end;

procedure TFormImagery.ImageDblClick(Sender: TObject);
begin
  Image.hide;
  LabelText.caption:='';
  PanelAVI.hide;
  PanelMP.width:=0;
  GaugeEnemy.progress:=0;
end;

procedure TFormImagery.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  FormMain.UnloadScreen(4);
end;

procedure TFormImagery.DoPlay;
begin
  if avis.count < 1 then exit;
  if isplaying then exit;
  if MP.filename = avis[0] then begin
    avis.delete(0);
    MP.play;
    isplaying:=true;
    BtnPlay.enabled:=false;
    BtnStop.enabled:=true;
    exit;
  end;
  MP.filename:=avis[0];
  avis.delete(0);
  PanelAVI.repaint;
  MP.open;
  MP.notify:=true;
  MP.play;
  isplaying:=true;
  BtnPlay.enabled:=false;
  BtnStop.enabled:=true;
end;

procedure TFormImagery.MPNotify(Sender: TObject);
begin
  isplaying:=false;
  if avis.count > 0 then begin
    DoPlay;
    exit;
  end;
  if BtnPlay.enabled then exit;
  if not MenuAutoRepeat.checked then begin
    BtnPlay.enabled:=true;
    BtnStop.enabled:=false;
    exit;
  end;
  MP.play;
  isplaying:=true;
end;

procedure TFormImagery.BtnPlayClick(Sender: TObject);
begin
  case TComponent(sender).tag of
    0: begin
         BtnStop.enabled:=false;
       end;
    1: begin
         MP.play;
         BtnPlay.enabled:=false;
         BtnStop.enabled:=true;
       end;
  end;
end;

procedure TFormImagery.MenuAutoRepeatClick(Sender: TObject);
begin
  TMenuItem(sender).checked:=not TMenuItem(sender).checked;
end;

end.
